package com.cishu.orancle.common;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * 自定义源数据处理器
 * */
@Component
@Slf4j
public class MyMetaObjectHandler implements MetaObjectHandler {

    /**
     * 插入数据自动填充
     * */
    @Override
    public void insertFill(MetaObject metaObject) {
        long cId = BaseContext.getCurrentId();
        metaObject.setValue("createTime", LocalDateTime.now());
        metaObject.setValue("updateTime", LocalDateTime.now());
        metaObject.setValue("createBy", cId);
        metaObject.setValue("updateBy", cId);
    }
    /**
     * 更新数据自动填充
     * */
    @Override
    public void updateFill(MetaObject metaObject) {
        long cId = BaseContext.getCurrentId();
        metaObject.setValue("updateTime", LocalDateTime.now());
        metaObject.setValue("updateBy", cId);
    }
}
